{% extends 'admin/base_admin.html' %}
{% block title %}{{ _('数据统计') }}{% endblock %}
{% block content %}
<form method="get" class="mb-4 flex gap-3 items-center">
  <label>{{ _('粒度') }}:
    <select name="bucket" class="border rounded p-1">
      <option value="day"   {{ 'selected' if bucket=='day'   else '' }}>{{ _('按日') }}</option>
      <option value="week"  {{ 'selected' if bucket=='week'  else '' }}>{{ _('按周') }}</option>
      <option value="month" {{ 'selected' if bucket=='month' else '' }}>{{ _('按月') }}</option>
    </select>
  </label>
  <label>{{ _('过去天数') }}:
    <input name="days" type="number" value="{{ days }}" min="1" max="365" class="border rounded p-1 w-24">
  </label>
  <button class="px-3 py-2 rounded bg-emerald-600 text-white">{{ _('刷新') }}</button>
</form>

<h3 class="font-semibold mb-2">{{ _('新用户数') }}</h3>
<table class="w-full text-sm border mb-6">
  <thead><tr><th class="p-2">Bucket</th><th class="p-2">{{ _('数量') }}</th></tr></thead>
  <tbody>
  {% for b, cnt in new_users.items() %}
    <tr class="border-t"><td class="p-2 font-mono">{{ b }}</td><td class="p-2">{{ cnt }}</td></tr>
  {% endfor %}
  </tbody>
</table>

<h3 class="font-semibold mb-2">{{ _('已支付订单数') }}</h3>
<table class="w-full text-sm border mb-6">
  <thead><tr><th class="p-2">Bucket</th><th class="p-2">{{ _('数量') }}</th></tr></thead>
  <tbody>
  {% for b, cnt in orders_paid.items() %}
    <tr class="border-t"><td class="p-2 font-mono">{{ b }}</td><td class="p-2">{{ cnt }}</td></tr>
  {% endfor %}
  </tbody>
</table>

<h3 class="font-semibold mb-2">{{ _('点击购买数（总计）') }}</h3>
<table class="w-full text-sm border mb-6">
  <thead><tr><th class="p-2">Bucket</th><th class="p-2">{{ _('数量') }}</th></tr></thead>
  <tbody>
  {% for b, cnt in clicks_total.items() %}
    <tr class="border-t"><td class="p-2 font-mono">{{ b }}</td><td class="p-2">{{ cnt }}</td></tr>
  {% endfor %}
  </tbody>
</table>

<h3 class="font-semibold mb-2">{{ _('点击购买数（按渠道）') }}</h3>
<table class="w-full text-sm border">
  <thead><tr><th class="p-2">Bucket</th><th class="p-2">direct</th><th class="p-2">email</th><th class="p-2">whatsapp</th><th class="p-2">wechat</th></tr></thead>
  <tbody>
  {% for b, m in clicks_by_channel.items() %}
    <tr class="border-t">
      <td class="p-2 font-mono">{{ b }}</td>
      <td class="p-2">{{ m.get('direct',0) }}</td>
      <td class="p-2">{{ m.get('email',0) }}</td>
      <td class="p-2">{{ m.get('whatsapp',0) }}</td>
      <td class="p-2">{{ m.get('wechat',0) }}</td>
    </tr>
  {% endfor %}
  </tbody>
</table>
{% endblock %}
